package com.qfjy.homework.WangYong;

/**
 * @author : 王勇
 * @version : 1.0
 * @date : 2022-06-29 18:59
 */
//创建实现 Container 接口的实体类
public class NameRepository implements Container{
    public String[] names = {"张三" , "李四" ,"王五" , "赵六"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    //创建实现 Iterator 接口的内部类 NameIterator
    private class NameIterator implements Iterator{

        int index;

        @Override
        public boolean hasNext() {
            if(index < names.length){
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if(this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
